/*Maximum Subsequence Sum：*/

#include <stdio.h>
#include <stdbool.h>

int max_seq_sum(int k, int a[], int *sub_seq) {
    int max_sum, curr_sum;
    curr_sum = 0;
    max_sum = 0;
    sub_seq[0] = a[0];
    bool flag = false;
    int thisi = a[0];
    for (int i = 0; i < k; i++) {
        curr_sum += a[i];
        if (a[i] >= 0) {flag = true;}
        if (a[i]==0 && sub_seq[0] < 0) {sub_seq[0] = a[i];sub_seq[1] = a[i];}
        if (curr_sum > max_sum) {
            sub_seq[1] = a[i];
            sub_seq[0] = thisi;
            max_sum = curr_sum;
        } else if (curr_sum < 0) {
            curr_sum = 0;
            if (i+1 < k) {thisi = a[i+1];}
        }
    }
    if (!flag) {
        sub_seq[0] = a[0];
        sub_seq[1] = a[k-1];
    }
    return max_sum;
}
int main(int argc, char *argv[]) {
    int k;
    scanf("%d", &k);
    int a[k];
    int sub_seq[2];
    for (int i = 0; i < k; i++) {
        scanf("%d", &a[i]);
    }
    int result = max_seq_sum(k, a, sub_seq);
    printf("%d %d %d\n", result, sub_seq[0], sub_seq[1]);
    return 0;
}